home *** CD-ROM | disk | FTP | other *** search
- /* environ.c
-
- This file contains routines to manipulate the system environment
- string on MSDOS. These routines assume that the assembly routine
- getenv2 has been used to initialize the values of enl and env.
- These routines were compiled with Microsoft's C compiler ver 4.0
- using the large memory model.
- Compile as : msc environ /AL;
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <string.h>
-
- extern char far *env; /* far pointer to system environment segment */
- char far *tem;
- extern int enl; /* system environment's size */
-
- char *search_for(str) /*searches environment for string*/
- char *str; /*string to search for*/
- {
- int l; /*scratch string length*/
-
- l=strlen(str); /*calculate length of argument string*/
- tem=env;
- while(*tem!=0) /*loop for all strings in environment*/
- {
- if (strnicmp(tem,str,l)==0) /*if you find it,*/
- return(tem); /*return a pointer to it*/
- while(*tem++ != 0); /*else, skip to next string*/
- }
- return(NULL); /*if no such string, return NULL*/
- }
-
- del_string(str) /*deletes a string from the environment*/
- char *str; /*name (including =) of string to delete*/
- {
- if (search_for(str) != NULL) /*if it exists,then whack it out!*/
- memcpy(tem,tem+strlen(tem)+1,(enl-(int)tem)-strlen(tem)-1);
- return;
- }
-
- int ins_string(str) /*insert a new string in the environment*/
- char *str; /*string (including name=) to add to environment*/
- {
- int l; /*length of string being inserted*/
-
- l=strlen(str); /*get length of new string*/
- if ((enl-(int)env)-l <=0) /*is there room for this?*/
- return(0); /*no, return zero*/
- tem=env;
- while(*tem != 0) /*loop until you find the double nul at end*/
- while (*tem++ != 0); /*skip past end of next string*/
- strcpy(tem,str); /*copy new string into the environment*/
- *(tem+l+1) = 0; /*write the second nul at the end*/
- return(1);
- }
-